<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String newsid=request.getParameter("id"); 
String fr=request.getParameter("fr"); 

%>

<!-- 企业资质上传 -->

<script type="text/javascript">
<!--

//-->
</script>
<style>
<!--
 	.btn_newsadd{
 		margin-left:50px; 
 	}
 	
-->
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" /> 
<link rel="stylesheet" type="text/css" href="<%=path %>/css/bootstrap.min.css" />
<script type="text/javascript" src="<%=path %>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=path %>/resources/date/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="<%=path %>/resources/date/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="<%=path %>/js/resources/common.js"></script>
<%-- ueditor js --%> 

	<script type="text/javascript" src="<%=path %>/js/resources/plupload/plupload.full.min.js"></script>

    <jsp:include page="common.jsp"></jsp:include>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li>系统设置</li>
    <li><span id="lujing">企业资质上传</span></li> 
    </ul>
    </div>
     
    <div class="formbody">
    
    <div class="formtitle"><span>基本信息</span></div>
    
    <ul class="forminfo">
    
    <li><label>图片alt</label><input name="img.imgAlt" id="imgAlt" type="text" class="dfinput" style="width:60%;"/><i>*图片没有找到显示的文字</i></li>
    <li><label>图片title</label><input name="img.imgTitle" id="imgTitle" type="text" class="dfinput" style="width:60%;"/><i>*鼠标移动到图片上显示的文字</i></li>
    <li> 
    	<button id="browse" name="uploadImage" class="btn btn-warning" style="margin-left:20px;">选择图片</button> 
    	<div style="float:left;margin-left:200px; ">
    		<img alt="" src="" id="yulan" style="width:200px;height:200px;">
    	</div>
		<!--<button id="start_upload" class="btn btn-warning">开始上传</button> -->
    </li>
    
    <li><label>&nbsp;</label>
    	<input name="" id="news_save" type="button" class="btn btn-primary btn_newsadd" value="确认保存"/>
    </li>
    </ul>
    
    
    
    </div>
    
 <script type="text/javascript" >
 
	 var path='<%=basePath%>';
	 var pid='<%=newsid%>';
	 var fr='<%=fr%>';
	 
	 /* 图片上传 */
	var uploader = new plupload.Uploader({
        browse_button : 'browse', //触发文件选择对话框的按钮，为那个元素id
        url : path+'/imagesAction_saveFile.action', //服务器端的上传页面地址
        filters : {
    		max_file_size : '10mb',
    		mime_types: [ 
    			{title : "Image files", extensions : "jpg,gif,png"}
    		]
    	},
    	multipart_params:{
    		"imgAlt":"",
    		"imgHref":"",
    		"imgTitle":"",
    		"type":"10"
    	}
    });  
	uploader.init();
	uploader.bind("Fileadded",function(up,f){
		previewImage(f[0],function(imgsrc){ 
			$("#yulan").attr("src",imgsrc); 
		});
	});
	
 	uploader.bind("FileUploaded",function(up,f,res){
 		res=eval('('+res.response+')');
		//TODO
		alert(res.msg);
		
		window.location.href="zizhilist.jsp";
		
 	});
 	
 	
 	function previewImage(file, callback) {//file为plupload事件监听函数参数中的file对象,callback为预览图片准备完成的回调函数
        if (!file || !/image\//.test(file.type)) return; //确保文件是图片
        if (file.type == 'image/gif') {//gif使用FileReader进行预览,因为mOxie.Image只支持jpg和png
            var fr = new mOxie.FileReader();
            fr.onload = function () {
                callback(fr.result);
                fr.destroy();
                fr = null;
            }
            fr.readAsDataURL(file.getSource());
        } else {
            var preloader = new mOxie.Image();
            preloader.onload = function () {
                //preloader.downsize(550, 400);//先压缩一下要预览的图片,宽300，高300
                var imgsrc = preloader.type == 'image/jpeg' ? preloader.getAsDataURL('image/jpeg', 80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
                callback && callback(imgsrc); //callback传入的参数为预览图片的url
                preloader.destroy();
                preloader = null;
            };
            preloader.load(file.getSource());
        }
    }
 
 $(function(){
	if(pid!=null && pid!="null"){ // 修改
		$("#lujing").text("新闻列表 > 新闻修改");
		$.post(path+"newsAction_details.action",{
			"uuid":'<%=newsid%>'
		},function(result){
			result=eval('('+result+')');
			if(result.rescode=='100'){
				var prod=result.data;
				$("input[name=title]").val(prod.title);
				$("input[name=subtitle]").val(prod.subtitle);
				$("input[name=sumary]").val(prod.sumary);
				$("input[name=newsTime]").val(moment(prod.newsTime).format('20YY年MMMDo hh:mm:ss'));
				$("#yulan").attr("src",path+prod.imgUrl);
				ue.ready(function () {
			        // editor准备好之后才可以使用
					ue.setContent(prod.content);
			        
			        if(fr=='show'){
			        	ue.setDisabled();
			        }
			        
				});
				
			}
		}); 
	
		
		//判断是显示详情还是编辑 
		
		if(fr=='show'){
			$("#lujing").text("新闻列表 > 新闻查看详情");
			$("input[name=title]").attr("disabled",true);
			$("input[name=subtitle]").attr("disabled",true);
			$("input[name=sumary]").attr("disabled",true);
			$("input[name=newsTime]").attr("disabled",true);
			/* ue.addListener("ready", function () {
		        // editor准备好之后才可以使用
				ue.setDisabled();
			}); */
			$("#news_save").attr("disabled",true);
			$("#news_reset").attr("disabled",true);
		}
	}else{//添加
	}
 });
 
 $("#news_save").unbind("click").bind("click",function(){
	 
		 
		 uploader.settings.multipart_params.imgAlt=$("#imgAlt").val();
		 uploader.settings.multipart_params.imgTitle=$("#imgTitle").val();
		 
		var fs=uploader.files.length;
		if(fs<=0){
			alert("请选择图片");
		}else{
				 // 上传图片
			uploader.start();
		} 
 });
 
 </script>